package com.gitee.qdbp.jdbc.operator.where;

import com.gitee.qdbp.able.jdbc.model.LikeValue;
import com.gitee.qdbp.jdbc.api.SqlBoot;
import com.gitee.qdbp.jdbc.operator.DbBinaryOperator;
import com.gitee.qdbp.jdbc.operator.base.DbAbstractOperator;
import com.gitee.qdbp.jdbc.sql.SqlBuffer;
import com.gitee.qdbp.jdbc.sql.SqlTools;

/**
 * 二元NotEndsWith运算符
 *
 * @author zhaohuihua
 * @version 20201102
 * @since 3.2.6
 */
public class DbBinaryNotEndsWithOperator extends DbAbstractOperator implements DbBinaryOperator {

    /** 版本序列号 **/
    private static final long serialVersionUID = 1L;

    public DbBinaryNotEndsWithOperator() {
        super("Not Ends With", "NotEndsWith", "Not Ends", "NotEnds");
    }

    @Override
    public SqlBuffer buildSql(String columnName, Object columnValue, SqlBoot sqlBoot) {
        if (columnValue instanceof LikeValue) {
            throw new IllegalArgumentException("EndsWith not support 'LikeValue', please use 'like'.");
        }
        String stringValue = columnValue == null ? null : SqlTools.unwrapDbVariable(columnValue).toString();
        return sqlBoot.newSqlBuilder().ad(columnName).ad("NOT").ad(sqlBoot.sqlDialect().buildEndsWithSql(stringValue)).out();
    }

}
